<?php
namespace plugins\pay\controller;
use plugins\pay\controller\BaseController;
use plugins\pay\lib\Pay;
class WechatpayController extends BaseController
{
    public $title = '微信';
    public $tag   = 'wechatpay';
    //配置页面
    public function config($var)
    {
        $configs = Pay::getConfigs($this->tag);
        $this->assign('configs', $configs);
        return $this->display($var);
    }
    //设置配置
    public function setConfig()
    {
        $data   = $this->request->param();
        $config = [
            "icon"              => '',
            "wechat_mchid"      => '',
            "wechat_key"        => '',
            'wechat_signtype'   => '',
            "wechat_appid"      => '',
            "wechat_secret"     => '',
            'wechat_proxy_host' => '',
            'wechat_proxy_port' => '',
            'wechat_trade_type' => '',
        ];
        if (isset($data['config'])) {
            $config = $data['config'];
        }
        $res = Pay::setConfigs($this->tag, $config);
        if (!$res) {
            return api_json_echo(false, '保存失败');
        }
        return api_json_echo(true, '保存成功');
    }
    /**
     * 回调地址
     */
    public function noticeurl()
    {
        $class = '\\plugins\\pay\lib\\' . strtolower($this->tag) . '\\' . cmf_parse_name($this->tag, 1);
        $pay   = new $class();
        $res   = $pay->notify();
    }
}
